package com.jeomo.sys.starter.mapper;

import com.jeomo.base.starter.mapper.IBaseMapper;
import com.jeomo.sys.starter.entity.Org;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 购物中心Mapper
 *
 * @Author: qbt
 * @Date: 2020/5/8 22:19
 * @Version 1.0
 */
@Mapper
public interface OrgMapper extends IBaseMapper<Org> {

    /**
     * 根据代码查询组织
     * @param code
     * @return
     */
    @Select("select * from sys_org where code = #{code}")
    Org queryByCode(String code);


    /**
     * 停用组织
     * @param code
     * @return
     */
    @Select("update sys_org set status = 2 where code = #{code}")
    void stop(String code);

    /**
     * 启用组织
     * @param code
     * @return
     */
    @Select("update sys_org set status = 1 where code = #{code}")
    void start(String code);


    /**
     * 查询组织最大代码
     * @return
     */
    @Select("select `code` from sys_org order by `code` desc LIMIT 1")
    String queryRecentlyCode();

    /**
     * 列出所有相关类型的组织
     * @param type 类型
     * @return
     */
    @Select("select * from sys_org where type = #{type}")
    List<Org> listByType(String type);

    /**
     * 查询子节点
     * @param parentCode
     * @return
     */
    @Select("select * from sys_org where parent_code = #{parentCode}")
    List<Org> listChildren(String parentCode);
}
